<template>
	<view class="container">
		<view class="form-wrap">
			<view class="form-item">
				<label>姓名</label>
				<input type="text" placeholder="请输入您的真实姓名" placeholder-class="pl" v-model="form.ali_name"/>
			</view>
			<view class="form-item">
				<label>卡号</label>
				<input type="text" placeholder="请输入您的银行卡账号" placeholder-class="pl" v-model="form.ali_account"/>
			</view>
			<view class="form-item">
				<label>开户行</label>
				<input type="text" placeholder="请输入您的开户行" placeholder-class="pl" v-model="form.ali_extra"/>
			</view>
		</view>
		<button class="btn base-btn line-center" :disabled="isDisabled" @tap='save'>确定保存</button>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				form:{
					ali_name:"",
					ali_account:'',
					ali_extra:''
				},
				isDisabled:false
			};
		},
		onLoad(option) {
			this.getCashDetail()
		},
		methods:{
			getCashDetail(){
				app.globalRequest({
					api:app.getApi().cash.cashContributionInfo,
				}).then(res=>{
					if (res.code == 0) {
						if(res.data.userAccount){
							this.form.ali_name = res.data.userAccount.ali_name;
							this.form.ali_account = res.data.userAccount.ali_account;
							this.form.ali_extra = res.data.userAccount.ali_extra;
						}
					} 
				})
			},
			save(){
				if(!this.form.ali_name){
					uni.showToast({
						title:'请输入您的真实姓名',
						icon:'none',
						mask:true
					})
					return;
				}
				if(!this.form.ali_account){
					uni.showToast({
						title:'请输入您的银行卡账号',
						icon:'none',
						mask:true
					})
					return;
				}
				if(!this.form.ali_extra){
					uni.showToast({
						title:'请输入您的开户行',
						icon:'none',
						mask:true
					})
					return;
				}
				app.globalRequest({
					api:app.getApi().user.aliAccount,
					method:"POST",
					data:this.form
				}).then(res=>{
					if(res.code == 0){
						uni.showToast({
							title:res.msg,
							icon:'none',
							mask:true
						})
						this.isDisabled = false;
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1000)
						
					}else{
						uni.showToast({
							title:res.msg,
							icon:'none',
							mask:true
						})
						this.isDisabled = false;
					}
				})
				
			}
		}
	}
</script>

<style lang="scss" scoped>
	.form-wrap{
		padding:30rpx 0 0;
	}
	.form-item{
		margin:0 24rpx;
		height:88rpx;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #F6F6F6;
		label{
			width: 118rpx;
			font-size: 28rpx;
			margin-right: 28rpx;
		}
		input{
			flex:1;
			height: 100%;
			font-size: 28rpx;
		}
	}
	.pl{
		font-size: 28rpx;
		color: #C1C1C1;
	}
	.btn{
		width: 686rpx;
		height: 84rpx;
		background: #1C1C1C;
		border-radius: 42rpx;
		margin:58rpx auto;
		color:#fff;
		font-size: 32rpx;
		font-weight: bold;
	}

</style>
